﻿using System;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CarMakeModelRSADB
/// </summary>
/// 
namespace CE.Provider
{

    public class CarMakeModelRSADB
    {
	    public CarMakeModelRSADB()
	    {
		    //
		    // TODO: Add constructor logic here
		    //
	    }

        public Int64 Insert(CarMakeModelRSA providercarmakemodelRSA)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarMakeModelRSAInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();
            #region Parameter

            _sPara.Add("@ProviderCarMakeModelRSAId", providercarmakemodelRSA.ProviderCarMakeModelRSAId);
            _sPara.Add("@ProviderCarMakeModelId", providercarmakemodelRSA.ProviderCarMakeModelId);
            _sPara.Add("@IsParallel", providercarmakemodelRSA.IsParallel);
            _sPara.Add("@Rate", providercarmakemodelRSA.Rate);
            _sPara.Add("@RefCEUserId", providercarmakemodelRSA.RefCEUserId);
            _sPara.Add("@Status", providercarmakemodelRSA.Status);
            _sPara.Add("@Finfo1", providercarmakemodelRSA.FInfo1);
            _sPara.Add("@Dinfo1", providercarmakemodelRSA.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Delete(Int64 ProviderCarMakeModelRSAId, Int64 ProviderCarMakeModelId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarMakeModelRSADeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarMakeModelRSAId", ProviderCarMakeModelRSAId);
            _sPara.Add("@ProviderCarMakeModelId", ProviderCarMakeModelId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;

        }


        public CarMakeModelRSA GetProviderCarMakeModelRSAItem(Int64 ProviderCarMakeModelId, Boolean IsParallel)
        {
            CarMakeModelRSA _providercarmakemodelRSA = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocProviderCarMakeModelRSASelectSingleItem]";
            
            SortedList _sPara = new SortedList();
            _sPara.Add("@ProviderCarMakeModelId", ProviderCarMakeModelId);
            _sPara.Add("@IsParallel", IsParallel);
            

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _sPara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _providercarmakemodelRSA = new CarMakeModelRSA();
                    _providercarmakemodelRSA = FillDataRecord(_dt, 0);
                }
            }
            return _providercarmakemodelRSA;
        }


        public CarMakeModelRSA GetProviderCarMakeRSAItemOnly(Int64 ProviderCarMakeModelId, byte @IsParallel)
        {
            CarMakeModelRSA _providercarmakemodelrsa = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocProviderCarMakeRSAOnlySelectSingleItem]";

            SortedList _sPara = new SortedList();
            _sPara.Add("@ProviderCarMakeModelId", ProviderCarMakeModelId);
            _sPara.Add("@IsParallel", @IsParallel);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _sPara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _providercarmakemodelrsa = new CarMakeModelRSA();
                    _providercarmakemodelrsa = FillDataRecord(_dt, 0);
                }
            }
            return _providercarmakemodelrsa;
        }
      

        private CarMakeModelRSA FillDataRecord(DataTable myDataTable, int rowId)
        {
            CarMakeModelRSA myProviderCarMakeModelRSA = new CarMakeModelRSA();
            myProviderCarMakeModelRSA.ProviderCarMakeModelRSAId =  Convert.ToInt64(myDataTable.Rows[rowId]["ProviderCarMakeModelRSAId"].ToString());
            myProviderCarMakeModelRSA.ProviderCarMakeModelId = Convert.ToInt64(myDataTable.Rows[rowId]["ProviderCarMakeModelId"].ToString());
            myProviderCarMakeModelRSA.IsParallel = Convert.ToBoolean(myDataTable.Rows[rowId]["IsParallel"].ToString());
            myProviderCarMakeModelRSA.Rate = Convert.ToInt32(myDataTable.Rows[rowId]["Rate"].ToString());
            myProviderCarMakeModelRSA.RefCEUserId = Convert.ToInt64(myDataTable.Rows[rowId]["RefCEUserId"].ToString());
            myProviderCarMakeModelRSA.Status = Convert.ToBoolean(myDataTable.Rows[rowId]["Status"].ToString());
   

            if (myDataTable.Rows[rowId]["FInfo1"].ToString() != "")
                myProviderCarMakeModelRSA.FInfo1 = Convert.ToSingle(myDataTable.Rows[rowId]["FInfo1"].ToString());

            if (myDataTable.Rows[rowId]["DInfo1"].ToString() != "")
                myProviderCarMakeModelRSA.DInfo1 = Convert.ToDateTime(myDataTable.Rows[rowId]["DInfo1"].ToString());
            else
                myProviderCarMakeModelRSA.DInfo1 = Convert.ToDateTime(myDataTable.Rows[rowId]["ModifiedDate"].ToString());

            return myProviderCarMakeModelRSA;
        }
    }
}
